package com.ruoyi.buss.task.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.task.domain.DataPlanTaskRelation;
import com.ruoyi.buss.task.service.IDataPlanTaskRelationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 总行营销计划关联Controller
 * 
 * @author sxy
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/taskPlanRelation")
public class DataPlanTaskRelationController extends BaseController
{
    @Autowired
    private IDataPlanTaskRelationService dataPlanTaskRelationService;

    /**
     * 查询总行营销计划关联列表
     */
    @PreAuthorize(hasPermi = "buss:taskPlanRelation:list")
    @GetMapping("/list")
    public TableDataInfo list(DataPlanTaskRelation dataPlanTaskRelation)
    {
        startPage();
        List<DataPlanTaskRelation> list = dataPlanTaskRelationService.selectDataPlanTaskRelationList(dataPlanTaskRelation);
        return getDataTable(list);
    }

    /**
     * 导出总行营销计划关联列表
     */
    @PreAuthorize(hasPermi = "buss:taskPlanRelation:export")
    @Log(title = "总行营销计划关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataPlanTaskRelation dataPlanTaskRelation) throws IOException
    {
        List<DataPlanTaskRelation> list = dataPlanTaskRelationService.selectDataPlanTaskRelationList(dataPlanTaskRelation);
        ExcelUtil<DataPlanTaskRelation> util = new ExcelUtil<DataPlanTaskRelation>(DataPlanTaskRelation.class);
        util.exportExcel(response, list, "总行营销计划关联数据");
    }

    /**
     * 获取总行营销计划关联详细信息
     */
    @PreAuthorize(hasPermi = "buss:taskPlanRelation:query")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") String taskId)
    {
        return AjaxResult.success(dataPlanTaskRelationService.selectDataPlanTaskRelationById(taskId));
    }

    /**
     * 新增总行营销计划关联
     */
    @PreAuthorize(hasPermi = "buss:taskPlanRelation:add")
    @Log(title = "总行营销计划关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataPlanTaskRelation dataPlanTaskRelation)
    {
        return toAjax(dataPlanTaskRelationService.insertDataPlanTaskRelation(dataPlanTaskRelation));
    }

    /**
     * 修改总行营销计划关联
     */
    @PreAuthorize(hasPermi = "buss:taskPlanRelation:edit")
    @Log(title = "总行营销计划关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataPlanTaskRelation dataPlanTaskRelation)
    {
        return toAjax(dataPlanTaskRelationService.updateDataPlanTaskRelation(dataPlanTaskRelation));
    }

    /**
     * 删除总行营销计划关联
     */
    @PreAuthorize(hasPermi = "buss:taskPlanRelation:remove")
    @Log(title = "总行营销计划关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable String[] taskIds)
    {
        return toAjax(dataPlanTaskRelationService.deleteDataPlanTaskRelationByIds(taskIds));
    }
}
